package experiment.service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import experiment.dao.UserDaoImpl;
import experiment.exception.BusiException;
import experiment.model.UserPOJO;
import experiment.response.ResultMsgEnum;
import experiment.utils.EncryptionUtil;


@Service
public class UserServiceImpl implements IUserService {
	
	@Autowired
	private UserDaoImpl userDaoImpl;
	
    public void login(UserPOJO user, HttpSession session) throws BusiException {
    	if(!userDaoImpl.selectByMap(user)) {
        	throw new BusiException(ResultMsgEnum.LOGIN_FAIL);
    	}
    	session.setAttribute("email", user.getEmail());
    }
    
    public Boolean register(UserPOJO user) {
    	UserPOJO userPOJO = new UserPOJO();
    	userPOJO.setEmail(user.getEmail());
    	if(userDaoImpl.selectByMap(userPOJO)) {
    		return false;
    	}else {
        	userDaoImpl.insert(user);
    		return true;
    	}
    }
    
    public Boolean hasPermission(String email) {
    	return userDaoImpl.hasPermission(email);
    }

}
